-- warning: import 'Prelude.Math' instead of this.

{-- 
    Mathematical functions from 'http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html java.lang.Math'.

    Functions that are already defined elsewhere, like @abs@ or @min@ have been left out.

    This module is not good for inclusion in user code, because of the overloaded
    primitive functions.
    
    Better use
    
    > import Prelude.Math
    
    which also defines the class 'Prelude.Math#Floating' that makes it possibly to use
    the primitive functions in a type safe way.
-}

protected module frege.java.lang.Math where

import frege.prelude.PreludeBase (Float, Double, Int, Long)

infixr 15  `**`

--- The 'Double' value that is closer than any other to e, the base of the natural logarithms.
pure native e         java.lang.Math.E        ∷ Double

--- The 'Double' value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
pure native pi        java.lang.Math.PI       ∷ Double

--- Returns the arc cosine of a value; the returned angle is in the range 0.0 through 'pi'.
pure native acos            java.lang.Math.acos     ∷ Float  → Double
                                                    | Double → Double

--- Returns the arc sine of a value; the returned angle is in the range -'pi'/2 through 'pi'/2.
pure native asin            java.lang.Math.asin     ∷ Float  → Double
                                                    | Double → Double

--- Returns the arc tangent of a value; the returned angle is in the range -'pi'/2 through 'pi'/2.
pure native atan            java.lang.Math.atan     ∷ Float  → Double
                                                    | Double → Double

--- Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
pure native atan2           java.lang.Math.atan2    ∷ Double → Double → Double
                                                    | Float  → Float  → Double

--- Returns the cube root of a value.
pure native cbrt            java.lang.Math.cbrt     ∷ Double → Double
                                                    | Float  → Double

--- Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer.
pure native ceil            java.lang.Math.ceil     ∷ Double → Double
                                                    | Float  → Double

--- Returns the first argument with the sign of the second argument.
pure native copySign        java.lang.Math.copySign ∷ Double → Double → Double
                                                    | Float  → Float  → Float

--- Returns the trigonometric cosine of an angle.
pure native cos             java.lang.Math.cos      ∷ Double → Double
                                                    | Float  → Double

--- Returns the hyperbolic cosine of a floating point value.
pure native cosh            java.lang.Math.cosh     ∷ Double → Double
                                                    | Float  → Double

--- Returns Euler's number 'e' raised to the power of a floating-point value.
pure native exp             java.lang.Math.exp      ∷ Double → Double
                                                    | Float  → Double

--- Returns @e^x -1@.
pure native expm1           java.lang.Math.expm1    ∷ Double → Double
                                                    | Float  → Double

{--
  Returns the largest (closest to positive infinity) value that is
  less than or equal to the argument and is equal to a mathematical integer.

  Special cases:

    - If the argument value is already equal to a mathematical integer,
    then the result is the same as the argument.
    - If the argument is NaN or an infinity or positive zero or
    negative zero, then the result is the same as the argument.

 -}
pure native floor           java.lang.Math.floor    ∷ Double → Double
                                                    | Float  → Double

--- Returns the unbiased exponent used in the representation of a floating point number.
pure native getExponent     java.lang.Math.getExponent 
                                                    ∷ Double → Int
                                                    | Float  → Int

--- Returns 'sqrt' @(x² + y²)@ without intermediate overflow or underflow.
pure native hypot           java.lang.Math.hypot    ∷ Double → Double → Double
                                                    | Float  → Float  → Double

--- Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.
pure native ieeeRemainder   java.lang.Math.IEEEremainder 
                                                    ∷ Double → Double → Double
                                                    | Float  → Float  → Double

--- Returns the natural logarithm (base 'e') of a value.
pure native log             java.lang.Math.log      ∷ Double → Double
                                                    | Float  → Double

--- Returns the base 10 logarithm of a value.
pure native log10           java.lang.Math.log10    ∷ Double → Double
                                                    | Float  → Double

--- Returns the natural logarithm of the sum of the argument and 1.
pure native log1p           java.lang.Math.log1p    ∷ Double → Double
                                                    | Float  → Double

--- Returns the floating-point number adjacent to the first argument in the direction of the second argument.
pure native nextAfter       java.lang.Math.nextAfter∷ Double → Double → Double
                                                    | Float  → Float  → Double

--- Returns the floating-point value adjacent to the argument in the direction of positive infinity.
pure native nextUp          java.lang.Math.nextUp   ∷ Double → Double
                                                    | Float  → Float

--- Returns the value of the first argument raised to the power of the second argument.
pure native **              java.lang.Math.pow      ∷ Double → Double → Double
                                                    | Float  → Float  → Double

--- Returns the value of the first argument raised to the power of the second argument.
pure native pow             java.lang.Math.pow      ∷ Double → Double → Double
                                                    | Float  → Float  → Double

--- Returns the 'Double' value that is closest in value to the argument and is equal to a mathematical integer.
pure native rint            java.lang.Math.rint     ∷ Double → Double
                                                    | Float  → Double

--- Returns the closest 'Long' to the argument, with ties rounding up.
pure native round           java.lang.Math.round    ∷ Double → Long
                                                    | Float  → Long

--- > scalb d scaleFactor
--- Return @d * 2^scaleFactor@ rounded as if performed by a single correctly rounded floating-point multiply.
pure native scalb           java.lang.Math.scalb    ∷ Double → Int → Double
                                                    | Float  → Int → Float

--- Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.
pure native signum          java.lang.Math.signum   ∷ Double → Double
                                                    | Float  → Float

--- Returns the trigonometric sine of an angle.
pure native sin             java.lang.Math.sin      ∷ Double → Double
                                                    | Float  → Double

--- Returns the hyperbolic sine of a value.
pure native sinh            java.lang.Math.sinh     ∷ Double → Double
                                                    | Float  → Double

--- Returns the correctly rounded positive square root of a value.
pure native sqrt            java.lang.Math.sqrt     ∷ Double → Double
                                                    | Float  → Double

--- Returns the trigonometric tangent of an angle.
pure native tan             java.lang.Math.tan      ∷ Double → Double
                                                    | Float  → Double

--- Returns the hyperbolic tangent of a floating point value.
pure native tanh            java.lang.Math.tanh     ∷ Double → Double
                                                    | Float  → Double

--- Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
pure native toDegrees       java.lang.Math.toDegrees∷ Double → Double
                                                    | Float  → Double

--- Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
pure native toRadians       java.lang.Math.toRadians∷ Double → Double
                                                    | Float  → Double

--- Returns the size of an ulp of the argument.
pure native ulp             java.lang.Math.ulp      ∷ Double → Double
                                                    | Float  → Float

